package com.zm.pay.controller;


import com.zm.api.service.IAccountTCCService;
import com.zm.api.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PayController {
    @Autowired
    private UserInfoService userInfoService;
    @RequestMapping("/pay/{userId}/{price}")
    @Transactional
    public boolean pay(@PathVariable Long userId,@PathVariable Long price){
        boolean result=false;
        if (userId!=null&&price!=null){
            result = userInfoService.pay(userId, price);
        }
        return result;
    }

///////////////////////////////////////////////////////////////////////////////////
    @Autowired
    private IAccountTCCService accountTCCService;
    @RequestMapping("/payTCC/{userId}/{price}")
    @Transactional
    public boolean payTCC(@PathVariable("userId") Long userId,@PathVariable("price") Long price){
        boolean result=false;
        try {
            if (userId!=null&&price!=null){
                Long l = accountTCCService.tryReduce(userId, price);
                result = (l!=0L?true:false);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
}
